/*
    Copyright 2012 Sven-Ove Bjerkan

    This file is part of KO-Ozi.

    KO-Ozi is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    KO-Ozi is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with KO-Ozi. If not, see <http://www.gnu.org/licenses/>.
*/
package com.koozi;

import java.util.Calendar;
import java.util.TimeZone;

/**
 * A class containing common, static methods
 * @author Sven-Ove Bjerkan
 */
public class TimeAndDate {
    
    /**
     * Get the current date on a "nice" format
     * @param separator separator to use between the parts of the date
     * @return yyyy<sep>mm<sep>dd
     */
    public static String getNiceDate(String separator) {
        String strMonth, strDay;
        // Use GMT+1 always, as the program is intended for use in Norway
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1"));

        // Get current day and add a "0" prefix if nessesary
        int day = cal.get(Calendar.DATE);
        strDay = (day < 10) ? ("0" + day) : (day + "");

        // Get current month and add a "0" prefix if nessesary
        int month = cal.get(Calendar.MONTH) + 1;
        strMonth = (month < 10) ? ("0" + month) : (month + "");

        int year = cal.get(Calendar.YEAR);

        return year + separator + strMonth + separator + strDay;
    }
    
    /**
     * Get the current time on a "nice" format
     * @param separator separator to use between the parts of the time
     * @return HH<sep>mm<sep>ss
     */
    public static String getNiceTime(String separator) {
        // Use GMT+1 always, as the program is intended for use in Norway
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1"));
        
        // Get current hour and add a "0" prefix if nessesary
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        String strHour = (hour < 10) ? ("0" + hour) : (hour + "");
        
        // Get current min and add a "0" prefix if nessesary
        int min = cal.get(Calendar.MINUTE);
        String strMin = (min < 10) ? ("0" + min) : (min + "");
        
        // Get current sec and add a "0" prefix if nessesary
        int sec = cal.get(Calendar.SECOND);
        String strSec = (sec < 10) ? ("0" + sec) : (sec + "");
        
        return strHour + separator + strMin + separator + strSec;
    }
}
